package com.protocolterminal.AFN.entity;

import java.util.ArrayList;
import java.util.List;

import com.protocolterminal.function.FrameFunction;

public class AFN0AF3 implements Interface_Data {

	@Override
	public String frametolist(String frame) throws Exception {
		List<String> list = new ArrayList<>();

		FrameFunction frameFunction = new FrameFunction();
		// 主ip
		list.add(String.valueOf(Integer.valueOf(frame.substring(0, 2), 16)) + "."
				+ String.valueOf(Integer.valueOf(frame.substring(2, 4), 16)) + "."
				+ String.valueOf(Integer.valueOf(frame.substring(4, 6), 16)) + "."
				+ String.valueOf(Integer.valueOf(frame.substring(6, 8), 16)));
		// 主端
		String temp = String.valueOf(Integer.valueOf(frameFunction.Reverse(frame.substring(8, 12)), 16));
		while (temp.length() < 4) {
			temp = "0" + temp;
		}
		list.add(temp);
		// 备用ip
		list.add(String.valueOf(Integer.valueOf(frame.substring(12, 14), 16)) + "."
				+ String.valueOf(Integer.valueOf(frame.substring(14, 16), 16)) + "."
				+ String.valueOf(Integer.valueOf(frame.substring(16, 18), 16)) + "."
				+ String.valueOf(Integer.valueOf(frame.substring(18, 20), 16)));
		// 备用端口
		temp = String.valueOf(Integer.valueOf(frameFunction.Reverse(frame.substring(20, 24)), 16));
		while (temp.length() < 4) {
			temp = "0" + temp;
		}
		list.add(temp);
		// apn
		temp = frame.substring(24, 56);
		byte[] bs = new byte[16];
		for (int i = 0; i < 16; i++) {
			bs[i] = Byte.valueOf(temp.substring(2 * i, 2 + 2 * i), 16);
		}
		list.add(new String(bs));

		String data = "";
		for (String string : list) {
			data += string + "-";
		}

		return data.substring(0, data.length() - 1);
	}

	@Override
	public String listtoframe(List<String> datalist) throws Exception {
		return "";
	}

}
